home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / win-fort.zip / WNDPROC.FOR < prev    next >
Text File  |  1991-11-11  |  13KB  |  305 lines

  1. $DEFINE KERNEL
  2. $DEFINE GDI
  3. $DEFINE USER
  4. $DEFINE CTLMGR
  5. $DEFINE MB
  6. $DEFINE MENUS
  7. $DEFINE RASTEROPS
  8. $DEFINE WINMESSAGES
  9.       INCLUDE 'WINDOWS.FI'
  10.       FUNCTION FWClockWndProc[PASCAL,FAR] (hWnd2,message,wParam,lParam)
  11.       IMPLICIT NONE
  12. C
  13. C Author       : Kevin B Black
  14. C Date written : 23-Oct-1991
  15. C Abstract     :
  16. C
  17. C Function to process Windows messages for FWClock
  18. C
  19.  
  20.       INTEGER*4 FWClockWndProc
  21.       INTEGER*2 hWnd2             ! Window handle, as passed by Windows
  22.       INTEGER*2 message           ! Type of message
  23.       INTEGER*2 wParam            ! Additional information
  24.       INTEGER*4 lParam            ! additional information
  25.  
  26.       INTEGER*4 lpProcAbout       ! Pointer to the "About" function
  27.  
  28.       INCLUDE 'WINDOWS.FD'        ! Include windows functions and parameters
  29.       EXTERNAL ABOUT [PASCAL,FAR] ! The About Box dialog procedure
  30.       INCLUDE 'FWCLOCK.FD'        ! Include FWClocks variables and parameters
  31.  
  32. C
  33. C Set a default return value
  34. C
  35.       FWClockWndProc=NULL
  36. C
  37. C See if this is a message that we process, unrecognised messages are passed
  38. C to the Windows default message handler, DefWindowProc.
  39. C
  40.       SELECT CASE (message)
  41. C
  42. C Command
  43. C
  44.          CASE (WM_COMMAND)                    ! Message: command from application menu
  45.             SELECT CASE (wParam)
  46. C
  47. C User has selected the chimes option from the menu. Swap chimes state, if
  48. C chimes state is being enabled, then chime now. Update Chimes keyword
  49. C in FWClocks profile file.
  50. C
  51.                CASE (IDM_CHIMES)
  52.                   IF(CHIMES)THEN
  53.                      CHIMES=.FALSE.
  54.                      WSTATUS=CheckMenuItem(GetMenu(hWnd2),wparam,
  55.      *                                                     MF_UNCHECKED)
  56.                      WSTATUS=WritePrivateProfileString('FWClock'C,
  57.      *                                                 'Chimes'C,
  58.      *                                                 NULLSTR,
  59.      *                                                 'FWCLOCK.INI'C)
  60.                   ELSE
  61.                      CHIMES=.TRUE.
  62.                      CALL MessageBeep(0)
  63.                      CALL MessageBeep(0)
  64.                      WSTATUS=CheckMenuItem(GetMenu(hWnd2),wparam,
  65.      *                                                       MF_CHECKED)
  66.                      WSTATUS=WritePrivateProfileString('FWClock'C,
  67.      *                                                 'Chimes'C,
  68.      *                                                 '1'C,
  69.      *                                                 'FWCLOCK.INI'C)
  70.                   ENDIF
  71. C
  72. C User has clicked on the Solid Hands menu option, this allows the user
  73. C to change between `solid' hands and outlines. The menu item is checked
  74. C if solid hands are selected. The new selection is written to the
  75. C FWClock profile file. After the hand type has changed, a pain message is
  76. C posted to the window, if it is `open', so that the new hands are drawn.
  77. C
  78.                CASE (IDM_SOLIDHANDS)
  79.                   IF(SOLIDHANDS)THEN
  80.                      SOLIDHANDS=.FALSE.
  81.                      WSTATUS=CheckMenuItem(GetMenu(hWnd2),wparam,
  82.      *                                                     MF_UNCHECKED)
  83.                      WSTATUS=WritePrivateProfileString('FWClock'C,
  84.      *                                                 'SolidHands'C,
  85.      *                                                 NULLSTR,
  86.      *                                                 'FWCLOCK.INI'C)
  87.                   ELSE
  88.                      SOLIDHANDS=.TRUE.
  89.                      WSTATUS=CheckMenuItem(GetMenu(hWnd2),wparam,
  90.      *                                                       MF_CHECKED)
  91.                      WSTATUS=WritePrivateProfileString('FWClock'C,
  92.      *                                                 'SolidHands'C,
  93.      *                                                 '1'C,
  94.      *                                                 'FWCLOCK.INI'C)
  95.                   ENDIF
  96.                   IF(.NOT.IMANICON)WSTATUS=
  97.      *                                   PostMessage(hWnd2,WM_PAINT,0,0)
  98. C
  99. C The user has clicked on the Second hand in Icon menu option. This allows
  100. C the user to enable/disable a second hand when the window is in the iconic
  101. C state. The new selection is written to the FWClock profile file. A paint
  102. C message is issued, if the window is in the iconic state, to update the
  103. C clock face.
  104. C
  105.                CASE (IDM_SECONDSICON)
  106.                   IF(SECONDSICON)THEN
  107.                      SECONDSICON=.FALSE.
  108.                      WSTATUS=CheckMenuItem(GetMenu(hWnd2),wparam,
  109.      *                                                     MF_UNCHECKED)
  110.                      WSTATUS=WritePrivateProfileString('FWClock'C,
  111.      *                                                 'SecondsInIcon'C,
  112.      *                                                 NULLSTR,
  113.      *                                                 'FWCLOCK.INI'C)
  114.                   ELSE
  115.                      SECONDSICON=.TRUE.
  116.                      WSTATUS=CheckMenuItem(GetMenu(hWnd2),wparam,
  117.      *                                                       MF_CHECKED)
  118.                      WSTATUS=WritePrivateProfileString('FWClock'C,
  119.      *                                                 'SecondsInIcon'C,
  120.      *                                                 '1'C,
  121.      *                                                 'FWCLOCK.INI'C)
  122.                   ENDIF
  123.                   IF(IMANICON)WSTATUS=PostMessage(hWnd2,WM_PAINT,0,0)
  124. C
  125. C User has selected time zone change from menu, this facility has not been
  126. C implimented yet, display a message box saying so...
  127. C
  128.                CASE (IDM_TIMEZONE)
  129.                   WSTATUS=MessageBox(hWnd2,
  130.      *                    'FWClock: Time Zone feature not implimented'C,
  131.      *                    'FWClock: Error'C,
  132.      *                      MB_APPLMODAL.OR.MB_ICONEXCLAMATION.OR.MB_OK)
  133. C
  134. C The user has clicked on the Exit menu option or closed the window. The
  135. C timer is killed off, the selected general tools are deleted and then
  136. C quit message is posted to let windows know FWClock has finished.
  137. C
  138.                CASE (IDM_EXIT)
  139.                   WSTATUS=KillTimer(hWnd2,MYTIMER)
  140.                   CALL DOWN_TOOLS
  141.                   CALL PostQuitMessage(0)
  142. C
  143. C The user has clicked on the About FWClock menu item, The About Box
  144. C dialog is created and displayed. The user must `ok' the about dialog
  145. C before the FWClock menu becomes accesssible again.
  146. C
  147.                CASE (IDM_ABOUT)
  148.                   lpProcAbout=MakeProcInstance(About,hInst)
  149.                   WSTATUS=DialogBox(hInst,    ! Current instance
  150.      *                           'AboutBox'C, ! Resource to use
  151.      *                           hWnd2,       ! Parent handle
  152.      *                           lpProcAbout) ! About() instance address
  153.                   CALL FreeProcInstance(lpProcAbout)
  154. C
  155. C If the menu item is not recognized, allow windows to process it. An
  156. C alternative would be to display a message box to inform the user.
  157. C
  158.                CASE DEFAULT                      ! Let Windows process it
  159.                   FWClockWndProc=DefWindowProc(hWnd2,message,
  160.      *                                                    wParam,lParam)
  161.             END SELECT
  162. C
  163. C The erase background message has been received, get the windows bounding
  164. C rectangle and paint it over with the background brush.
  165. C
  166.          CASE (WM_ERASEBKGND)                 ! Erase background
  167.             CALL GetClientRect(hWnd2,TRECT)
  168.             WSTATUS=FillRect(wParam,TRECT,BBRUSH)
  169. C
  170. C The paint message has been received, the whole of the clock must be
  171. C painted.....
  172. C
  173.          CASE (WM_PAINT)
  174. C
  175. C Invalidate the current window contents
  176. C
  177.             CALL InvalidateRect_A(hWnd2,0,1)
  178. C
  179. C Begin paint, this call is important, and it should only be activated in
  180. C response to the WM_PAINT message. It must be matched with a call to the
  181. C EndPaint function, before returning from the programs windows function.
  182. C
  183.             WSTATUS=BeginPaint(hWnd2,FWCPS)
  184. C
  185. C Set background mode and select the tools required
  186. C
  187.             WSTATUS=SetBkMode(FWCPS.HDC,TRANSPARENT)
  188.             WSTATUS=SelectObject(FWCPS.HDC,FPEN)
  189.             WSTATUS=SelectObject(FWCPS.HDC,FBRUSH)
  190. C
  191. C Draw the clock face
  192. C
  193.             WSTATUS=SetROP2(FWCPS.HDC,R2_COPYPEN)
  194.             CALL DRAW_FACE
  195. C
  196. C Put on the minute and hour hands
  197. C
  198.             CALL DRAW_HOURHAND
  199.             CALL DRAW_MINUTEHAND
  200. C
  201. C Put on the second hand. The current screen contents under the second hand
  202. C are inverted so that it always shows up. A second hand is only required
  203. C if the window is open, or the user has enabled it for the windows iconic
  204. C state. In the non-iconic state a `hub' is draw at the centre of the clock
  205. C face (just like a real clock!).
  206. C
  207.             IF(.NOT.IMANICON.OR.SECONDSICON)THEN
  208.                WSTATUS=SetROP2(FWCPS.HDC,R2_NOT)
  209.                CALL DRAW_SECONDHAND
  210.                WSTATUS=SetROP2(FWCPS.HDC,R2_COPYPEN)
  211.                IF(.NOT.IMANICON)CALL DRAW_HUB
  212.             ENDIF
  213. C
  214. C Finished painting the window, so tell windows.
  215. C
  216.             CALL EndPaint(hWnd2,FWCPS)
  217. C
  218. C The window has been resized, this includes conversions to and from the
  219. C iconic state. Windows should issue a WM_PAINT message after a window
  220. C has been resized, so that should take care of redrawing the window.
  221. C
  222.          CASE (WM_SIZE)                       ! Window re-sized
  223.             CALL RESIZE(hWnd2,lParam,wParam) 
  224. C
  225. C The timer has expired, or the system time has been changed by the user.
  226. C The clock face needs to be updated if the time has changed (the timer
  227. C fires more often then the time on the clock face changed, so that the
  228. C motion of the hand, the second hand especially, is smooth).
  229. C
  230.          CASE (WM_TIMER,WM_TIMECHANGE)        ! Timer triggered or system time changed
  231. C
  232. C Get the current time, and see if the clock face needs to be updated.
  233. C
  234.             CALL GETTIM(HOURS,MINS,SECS,WSTATUS)
  235.             IF((OSECS.NE.SECS.AND.(.NOT.IMANICON.OR.SECONDSICON)).OR.
  236.      *          OMINS.NE.MINS.OR.OHOURS.NE.HOURS)THEN
  237. C
  238. C The clock face needs updating, get a handle on the window, and if there
  239. C is a second hand on display, erase it.
  240. C
  241.                FWCPS.HDC=GetDC(hWnd2)
  242.                IF(.NOT.IMANICON.OR.SECONDSICON)THEN
  243.                   WSTATUS=SetROP2(FWCPS.HDC,R2_NOT)
  244.                   CALL DRAW_SECONDHAND        ! Erase old second hand
  245.                ENDIF
  246. C
  247. C If the minute has changed (or the hour, in case the clock was held up
  248. C for an hour (in which case the minute might be the same) then erase
  249. C and redraw the hour and minute hands to `move' them `arround' the clock
  250. C face.
  251. C
  252.                IF(MINS.NE.OMINS)THEN
  253.                   WSTATUS=SetROP2(FWCPS.HDC,R2_COPYPEN)
  254.                   WSTATUS=SelectObject(FWCPS.HDC,BPEN)
  255.                   WSTATUS=SelectObject(FWCPS.HDC,BBRUSH)
  256.                   CALL DRAW_HOURHAND
  257.                   CALL DRAW_MINUTEHAND
  258.                   OHOURS=HOURS
  259.                   OMINS=MINS
  260. C                  WSTATUS=SetROP2(FWCPS.HDC,R2_COPYPEN)
  261.                   WSTATUS=SelectObject(FWCPS.HDC,FPEN)
  262.                   WSTATUS=SelectObject(FWCPS.HDC,FBRUSH)
  263.                   CALL DRAW_HOURHAND
  264.                   CALL DRAW_MINUTEHAND
  265.                   IF(OHOURS.NE.HOURS)THEN
  266.                      CALL MessageBeep(0)
  267.                      CALL MessageBeep(0)
  268.                   ENDIF
  269.                ENDIF
  270. C
  271. C If a second hand should be on display, then put it on. For a non-iconic
  272. C clock face, the hub is redrawn (to erase where the hands have overlapped
  273. C it).
  274. C
  275.                OSECS=SECS
  276.                IF(.NOT.IMANICON.OR.SECONDSICON)THEN
  277.                   WSTATUS=SetROP2(FWCPS.HDC,R2_NOT)
  278.                   CALL DRAW_SECONDHAND     ! Draw new second hand
  279.                   WSTATUS=SetROP2(FWCPS.HDC,R2_COPYPEN)
  280.                   IF(.NOT.IMANICON)CALL DRAW_HUB
  281.                ENDIF
  282. C
  283. C The clock has been updated, release the device contect for the window.
  284. C
  285.                WSTATUS=ReleaseDC(hWnd2,FWCPS.HDC)
  286.             ENDIF
  287. C
  288. C The destroy window message has been received. As with the Exit option
  289. C on the menu, the timer is killed off and the selected general tools are
  290. C deleted. A quit message is then posted to windows to tell it the
  291. C application has finished.
  292. C
  293.          CASE (WM_DESTROY)                    ! message: window being destroyed
  294.             CALL DOWN_TOOLS
  295.             WSTATUS=KillTimer(hWnd2,MYTIMER)
  296.             CALL PostQuitMessage(0)
  297. C
  298. C If the message was not recognized, then let windows have it
  299. C
  300.          CASE DEFAULT                         ! Passes it on if unproccessed
  301.             FWClockWndProc=DefWindowProc(hWnd2,message,wParam,lParam)
  302.       END SELECT
  303.       RETURN
  304.       END
  305.